package lv.ante.dziesmas.raster;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.geom.AffineTransform;
import java.awt.image.RenderedImage;

import javax.swing.JPanel;

/**
 * Very simple class for displaying RenderedImages
 */
public class Ch6Display extends JPanel {
	public Ch6Display(RenderedImage image) {
		super();
		source = image;
		setPreferredSize(new Dimension(source.getWidth(), source.getHeight()));
	}

	public synchronized void paintComponent(Graphics g) {
		Graphics2D g2d = (Graphics2D) g;
		// account for borders and source image offsets
		Insets insets = getInsets();
		int tx = insets.left - source.getMinX();
		int ty = insets.top - source.getMinY();
		AffineTransform af;
		af = AffineTransform.getTranslateInstance(tx, ty);
		// Translation moves the entire image within the container
		g2d.drawRenderedImage(source, af);
	}

	protected RenderedImage source = null;
}